<?php
namespace app\index\controller;

use think\Db;

class Index extends Base
{
    public function index()
    {
        return view();
    }
    public function login ()
    {
        return view();
    }

    public function checkLogin ()
    {

        $post = input('post.' , '' , 'htmlspecialchars');
        if ($post['phone'] == session('phone') && $post['yzcode'] == session('code')) {
            $info = db('member')->where('phone' , $post['phone'])->find();
            if (!$info) {
                $this->redirect('item');
            }else {
                $this->redirect( 'erdu');
            }
        }else {
            $this->error('手机号码或短信验证码不正确');
        }
    }

    public function sendMessage ()
    {
        $post = input('post.');
        $code = mt_rand(1000 , 9999);
        session('phone' , $post['phone']);
        session('code' , $code);
//        dump($post);die;
        $url = 'http://v.juhe.cn/sms/send?mobile='.$post['phone'].'&tpl_id=115034&tpl_value=%23code%23%3D'.$code.'&key=2f524705d0380ff37b64dda6fe032266';
        $res = get($url);
        return json_decode($res);

    }

    public function input ()
    {
        return view();
    }
    public function item ()
    {
        if (session('phone') == null) {
            $this->redirect('login');
        }
        $info = db('member')->where('phone' , session('phone'))->find();
        if(session('phone') == $info['phone']) {
            $this->redirect('erdu');
        }

        return view();
    }

    public function save_items ()
    {
        $post = input('post.');
        $post['time'] = time();
        db('member')->insertGetId($post);
        session('name' , $post['name']);
        session('certificate' , $post['certificate']);
        session('card' , $post['card']);
        session('quotas' , $post['quotas']);
        return json(['status' => 1]);

    }

    public function erdu ()
    {
        $info = db('member')->where('phone' , session('phone'))->find();
        $this->assign('info' , $info);
        return view();
    }
    public function shenhe ()
    {
        return view();
    }

    public function pay ()
    {
        $qrcode = db('config')->where('name' , 'qrcode')->find();
        $info = db('member')->where('phone' , session('phone'))->find();
        $this->assign('info' , $info);
        $this->assign('qrcode' , $qrcode['value']);
        return view();
    }
    public function sure ()
    {
        $info = db('member')->where('phone' , session('phone'))->find();
        $this->assign('info' , $info);
        return view();
    }

    public function build ()
    {
        $get = input('get.');
        $this->assign('get' , $get);
        return view();
    }
}
